package com.how2java.springboot.web;

import com.how2java.springboot.po.SystemUserPO;
import com.how2java.springboot.service.SystemUserService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/users")
public class SystemUserController {

    private final SystemUserService systemUserService;

    public SystemUserController(SystemUserService systemUserService) {
        this.systemUserService = systemUserService;
    }

    // 查询所有用户
    @GetMapping
    public List<SystemUserPO> getAllUsers() {
        return systemUserService.list();
    }

    // 根据ID查询
    @GetMapping("/{id}")
    public SystemUserPO getUserById(@PathVariable Long id) {
        return systemUserService.getById(id);
    }

    // 新增
    @PostMapping
    public boolean addUser(@RequestBody SystemUserPO user) {
        return systemUserService.save(user);
    }

    // 删除
    @DeleteMapping("/{id}")
    public boolean deleteUser(@PathVariable Long id) {
        return systemUserService.removeById(id);
    }
}
